package com.zzy.backend.service.impl.user.bot;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzy.backend.mapper.BotMapper;
import com.zzy.backend.pojo.Bot;
import com.zzy.backend.pojo.User;
import com.zzy.backend.service.impl.utils.UserDetailsImpl;
import com.zzy.backend.service.user.bot.GetListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author molimark<br />
 * @date: 2023/3/11 9:24<br/>
 * @description: <br/>
 */

@Service
public class GetListServiceImpl implements GetListService {
    @Autowired
    private BotMapper botMapper;

    @Override
    public List<Bot> getList() {
        UsernamePasswordAuthenticationToken authenticationToken =
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

        UserDetailsImpl loginUser = (UserDetailsImpl) authenticationToken.getPrincipal();
        User user = loginUser.getUser();

        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("user_id",user.getId());
        return botMapper.selectList(qw);
    }
}
